package com.qys.livesMall.event.listener;

import com.qys.livesMall.app.user.event.AppUserWithdrawalEvent;
import com.qys.livesMall.app.user.model.dto.app.AppUserApplyWithdrawalDTO;
import com.qys.livesMall.app.user.service.UserStatisticsInfoService;
import com.qys.livesMall.app.user.service.UserStatisticsTeamService;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

@Slf4j
@RequiredArgsConstructor
public class AppUserApplyWithdrawalListener {

    private final UserStatisticsTeamService userStatisticsTeamService;

    private final UserStatisticsInfoService userStatisticsInfoService;

    @Async
    @Order
    @EventListener(AppUserWithdrawalEvent.class)
    public void saveUserRechargeInfo(AppUserWithdrawalEvent appUserWithdrawalEvent){
        AppUserApplyWithdrawalDTO appUserApplyWithdrawalDTO= (AppUserApplyWithdrawalDTO) appUserWithdrawalEvent.getSource();
        userStatisticsTeamService.editWaitWithdrawal(appUserApplyWithdrawalDTO);
        userStatisticsInfoService.updatePendingWithdrawal(appUserApplyWithdrawalDTO);
    }
}
